<?php

/**
 * Manage "ideal_profile" table 
 * 
 * @property int $ideal_profile_id
 * @property int $user_id
 * @property int $marital
 * @property int $ethnicity
 * @property int $relationship
 * @property int $zodiac
 * @property int $smoking
 * @property int $height_from 
 * @property int $height_to
 * @property int $general_build
 * @property int $children
 * @property int $religion 
 * @property int $age_from
 * @property int $age_to 
 */
class IdealProfile extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return User the static model class
     */
    public static function model($className = __CLASS__) {
	return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
	return '{{ideal_profile}}';
    }

    public function relations() {
	return array(
	    'user' => array(self::BELONGS_TO, 'User', 'user_id')
	);
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
	return array(
	    array('age_from', 'compare', 'compareAttribute' => 'age_to', 'operator' => '<', 'message' => 'Age From must be less than Age To'),
	    array('height_from', 'compare', 'compareAttribute' => 'height_to', 'operator' => '<', 'message' => 'Height From must be less than Heihgt To'),
	    array('marital, ethnicity, relationship, zodiac, smoking, general_build, children, religion, age_from, age_to, height_to', 'safe')
	);
    }

    public static function getIdealProfile($id) {
	$aRow = Yii::app()->db->createCommand('SELECT * FROM {{ideal_profile}} WHERE user_id=' . $id)->queryRow();
	if ($aRow)
	    return $aRow;
	return array();
    }

}
